package com.zzw.quartztest.job;

import com.zzw.quartztest.service.impl.QuartzTestServiceImpl;
import org.apache.commons.lang3.time.DateUtils;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TestConcurrencyJob implements org.quartz.Job {

    private static final Logger logger = LoggerFactory.getLogger(TestConcurrencyJob.class);

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        if (logger.isDebugEnabled()) {
            JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
            // 获取构建任务时存储的数据
            Long jobId = (Long) jobDataMap.get(QuartzTestServiceImpl.JOB_DATA_KEY);
            logger.debug("定时任务{}执行：" + TestConcurrencyJob.getTime(), jobId);
        }
    }

    private static String getTime() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(new Date());
    }
}
